<template>
	<view>
		<navigationbar
			:leftText="leftText"
		/>
		<view class="content">
			<view class="search">
				<u-search :clearabled="true" placeholder="搜索职位/公司" v-model="keyword" @search="search" @custom="search"></u-search>
			</view>
			<view class="historySearch">
				<text>历史搜索</text>
				<text @click="deletes" class="iconfont icon-shanchu"></text>
				<view class="item">
					<text :key=index v-for="(item,index) in hItemList" @click="search(item)">{{item}}</text>
				</view>
			</view>
			<view class="found">
				<text>搜索推荐</text>
				<view class="item">
					<text :key=index v-for="(item,index) in tItemList" @click="search(item)">{{item}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import navigationbar from '../navigationBar.vue'
export default {
	components:{
		navigationbar
	},
	data() {
		return {
			hItemList: [''],
			tItemList: ['前端开发','人工智能','大数据','java','react','ui软件设计','ue4图形工程师'],
			leftText: '职位搜索',
			leftIcon: 'map',
			keyword: ''
		};
	},
	onShow() {
		uni.getStorage({
			key: 'history',
			success: (res) => {
				this.hItemList = res.data
			}
		})
	},
	methods: {
		search(_data) {
			uniCloud.callFunction({
				name: 'getSearchData',
				data:{
					search: _data
				},
				success: (res) => {
					this.$store.commit('setSearchData', res.result.data)
					uni.navigateTo({
						url: 'searchList/searchList',
					})
					this.hItemList.unshift(_data)
					if(this.hItemList.length > 5) {
						this.hItemList.pop()
					}
					uni.setStorage({
						key: 'history',
						data: this.hItemList
					})
				}
			})
		},
		deletes(){
			this.hItemList = []
			console.log('删除历史搜索！')
			uni.removeStorage({
				key: 'history',
			})
		}
	}
};
</script>

<style lang="scss">
	.content{
		width: 100%;
		.search{
			width: 90%;
			margin: 10rpx auto;
			padding-bottom: 5px;
			border-bottom: 1rpx solid #f2f2f2;
		}
		.historySearch{
			width: 90%;
			height: 180rpx;
			margin: 20px auto;
			font-size: 40rpx;
			&>text{
				font-weight: bold;
			}
			.item{
				white-space: pre-wrap;
				width: 100%;
				height: 50%;
				margin-top: 50rpx;
				text{
					font-size: 30rpx;
					width: auto;
					display: inline-block;
					padding: 8rpx 20rpx;
					margin:0 20rpx 30rpx 0;
					background-color: #f2f2f2;
					border-radius: 10rpx;
				}
			}
			.iconfont {
				float: right;
			}
		}
		.found{
			width: 90%;
			height: 500rpx;
			margin: 80px auto;
			font-size: 40rpx;
			&>text{
				font-weight: bold;
			}
			.item{
				font-size: 30rpx;
				white-space: pre-wrap;
				height: 50%;
				margin-top: 50rpx;
				text{
					display: inline-block;
					padding: 8rpx 20rpx;
					margin:0 20rpx 30rpx 0;
					background-color: #f2f2f2;
					border-radius: 10rpx;
				}
			}
		}
	}
</style>
